<?php

if(array_key_exists("PATH_INFO" , $_SERVER)) {
  $path_info = $_SERVER["PATH_INFO"];
} else {
  $path_info = "/";
}

$path_infos = explode("/", $path_info);
$path_count = count($path_infos);

if( $path_count == 3) {
  $path = $path_infos[ 1 ];
  $filename = $path_infos[ 2 ];
} elseif ( strlen( $path_infos[ 1 ]) != 0 ) {
  $path = "index";
  $filename = $path_infos[ 1 ];
} else {
  $path = "index";
  $filename = "index";
}

include_once( "./views/" . $path . "/" . $filename . ".html");

//01.先判断是否写入了地址
// if(array_key_exists("PATH_INFO",$_SERVER)) {
//   //true 说明写入了地址
//   $path_info = $_SERVER["PATH_INFO"];
// } else {
//   //false 说明没有写地址 
//   $path_info = "/";
// }

// //02.判断写入的地址的长度 0个 1个 2个？
// //用 / 来分割字符串 返回一个数组 explode()--切割字符串 count()--返回数组的长度
// //'/' ---- ['', '']
// //'/login' ---- ['', 'login']
// //'/index/login' ---- ['','index','login']
// $path_infos = explode("/", $path_info); //数组
// $path_count = count($path_infos);

// if( $path_count == 3 ) {
//   //说明有两个路径  ['','index','login']
//   $path = $path_infos[ 1 ];
//   $filename = $path_infos[ 2 ];

// } elseif ( strlen($path_infos[ 1 ]) != 0 ) {
//   //说明有一个路径 ['', 'login']
//   $path = "index";
//   $filename = $path_infos[ 1 ];
// } else {
//   //说明为 /  ['', '']
//   $path = "index";
//   $filename = "index";
// }

// //03.拼接字符串 
// //http://tea.com/index.php/views/index/login.html
// //http://tea.com/index.php + './views/' + $path + '/' + $filename + '.html'
// include_once("./views/" . $path . "/" . $filename . ".html");

?>